package com.xyd.Servlet;

import com.xyd.Biz.CommonTableBiz;
import com.xyd.Biz.Impl.CommonTableBizImpl;
import com.xyd.Entity.CommonTable;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/html/manage/SubmitUpdateCommonTableServlet")
public class SubmitUpdateCommonTableServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String id = request.getParameter("commonid");
        String parentId = request.getParameter("parentId");
        String className = request.getParameter("className");


        CommonTableBiz commonTableBiz = new CommonTableBizImpl();
        CommonTable commonTable = commonTableBiz.getCommonTableById(Integer.parseInt(id));

        if (parentId == "0") {
            commonTable.setType_char("OneTittle");
            commonTable.setType_name(className);
            commonTable.setType_value("T_" + className);
            commonTable.setVal_type(1);
            commonTableBiz.updateCommonTableById(commonTable);
            request.getRequestDispatcher("manage-result.jsp").forward(request,response);
        } else {
            commonTable.setType_char("TowTittle");
            commonTable.setType_name(className);
            commonTable.setType_value("T_" + className);
            commonTable.setOftype(parentId);
            commonTable.setVal_type(1);
            commonTableBiz.updateCommonTableById(commonTable);
            request.getRequestDispatcher("manage-result.jsp").forward(request,response);
        }
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req, resp);
    }
}
